//
//  BottomView.swift
//  SinaBlog
//
//  Created by macs on 15/11/14.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

import UIKit
import SnapKit
class BottomView: UIView {
    
    
    @objc private func retweeteBtnDidClick() {
        
        print(retweeteBtn.getNavgationController())
        let tempVc = TempViewController()
        retweeteBtn.getNavgationController()?.pushViewController(tempVc, animated: true)
        
    }
    
    //3.重写构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor(white: 0.98, alpha: 1)
        setupUI()
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //2.添加子控件,设置约束
    //MARK : wenti 小于0.8不可见?
    
    let sepW = 0.8
    let sepScale = 0.6
    func setupUI() {
        addSubview(retweeteBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        
        retweeteBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(snp_left)
            make.top.equalTo(snp_top)
            make.height.equalTo(snp_height)
        }
        
        let sepV1 = sepView()
        addSubview(sepV1)
        sepV1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweeteBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.width.equalTo(sepW)
            make.height.equalTo(retweeteBtn.snp_height).multipliedBy(sepScale)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweeteBtn.snp_right)
            make.top.equalTo(retweeteBtn.snp_top)
            make.height.equalTo(retweeteBtn.snp_height)
            make.width.equalTo(retweeteBtn.snp_width)
        }
        
        let sepV2 = sepView()
        addSubview(sepV2)
        sepV2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.width.equalTo(sepW)
            make.height.equalTo(retweeteBtn.snp_height).multipliedBy(sepScale)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.top.equalTo(retweeteBtn.snp_top)
            make.right.equalTo(snp_right)
            make.height.equalTo(retweeteBtn.snp_height)
            make.width.equalTo(retweeteBtn.snp_width)
        }
        
        retweeteBtn.addTarget(self, action: "retweeteBtnDidClick", forControlEvents: .TouchUpInside)
        
    }
    
    
    
    //1.懒加载控件
    lazy var retweeteBtn : UIButton = UIButton(title: "转发", color: UIColor.darkGrayColor(), icon: nil,image : "timeline_icon_retweet",size: 10)
    lazy var commentBtn : UIButton = UIButton(title: "评论", color:  UIColor.darkGrayColor(), icon: nil,image : "timeline_icon_comment",size: 10)
    lazy var likeBtn : UIButton = UIButton(title: "赞", color:  UIColor.darkGrayColor(), icon: nil,image :"timeline_icon_unlike",size: 10)
    
    //分割线
    private func sepView () -> UIView {
        
        let v = UIView()
        v.backgroundColor = UIColor.lightGrayColor()
        return v
    }
}
